﻿using FriendStar.Code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using FriendStar.Application.SystemManage;
using FriendStar.Application.WareHouse;
using FriendStar.Domain.Entity.WareHouse;
using FriendStar.Repository.Infrastructure;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Text;
using System.Web.Script.Serialization;
using FriendStar.Application.VBaseData;

namespace FriendStar.Web.Areas.WareHouse.Controllers
{
    public class EnterWareHouseController : ControllerBase
    {
        private CPK_11_DJ_StoRegisterApp cpk_11_DJ_StoRegisterApp = new CPK_11_DJ_StoRegisterApp();
        private CPK_41_ML_StoCPKConAccoApp cpk_41_ML_StoCPKConAccoApp = new CPK_41_ML_StoCPKConAccoApp();
        private CPK_42_MX_StoCPKListAccoApp cpk_42_MX_StoCPKListAccoApp = new CPK_42_MX_StoCPKListAccoApp();
        private CPK_21_CC_StoStorageCardApp cpk_21_CC_StoStorageCardApp = new CPK_21_CC_StoStorageCardApp();
        private V_CPK_21_CC_StoStorageCardApp v_cpk_21_CC_StoStorageCardApp = new V_CPK_21_CC_StoStorageCardApp();
        private V_CPK_22_CK_StoStorageCard_MidApp v_cpk_22_CK_StoStorageCard_MidApp = new V_CPK_22_CK_StoStorageCard_MidApp();
        private CPK_31_BL_StoArcPreMaterialApp cpk_31_BL_StoArcPreMaterialApp = new CPK_31_BL_StoArcPreMaterialApp();
        private V_CPK_A1_BB_StoProStockCata_RBApp dutyApp = new V_CPK_A1_BB_StoProStockCata_RBApp();

        private ModuleApp moduleApp = new ModuleApp();
        private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
        private StoCPKConAccoForInStockApp stoCPKConAccoForInStockApp = new StoCPKConAccoForInStockApp();
        private StoCPKConAccoForOutStockApp stoCPKConAccoForOutStockApp = new StoCPKConAccoForOutStockApp();
        private StoCPKConAccoForInventoryStockApp stoCPKConAccoForInventoryStockApp = new StoCPKConAccoForInventoryStockApp();
        private StoCPKConAccoForUnqualifiedStockApp stoCPKConAccoForUnqualifiedStockApp = new StoCPKConAccoForUnqualifiedStockApp();
        private StoCPKConAccoForReturnRemainApp stoCPKConAccoForReturnRemainApp = new StoCPKConAccoForReturnRemainApp();
        private string useUnit = Configs.GetValue("UseUnit");
        private string factoryFlag = Configs.GetValue("FactoryFlag");
        private string curUser = OperatorProvider.Provider.GetUserName();

        public ActionResult GetGridJson(string keyword)
        {
            var data = cpk_11_DJ_StoRegisterApp.GetList(keyword);
            return Content(data.ToJson());
        }
        //
        // GET: /WareHouse/EnterWareHouse/

        public ActionResult WareHousePick()//领料通知
        {
            return View();
        }


        public ActionResult WareHousePickInput()//领料通知输入
        {
            return View();
        }

        #region 来料登记
        /// <summary>
        /// 保存来料登记信息
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public ActionResult SaveDJ_StoRegister(CPK_11_DJ_StoRegisterEntity item)
        {
            cpk_11_DJ_StoRegisterApp.SubmitForm(item, item.FRegisterID);
            return Success("操作成功。");
        }

        /// <summary>
        /// 删除来料登记信息
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public ActionResult DeleteDJ_StoRegister(string keyValue)
        {
            cpk_11_DJ_StoRegisterApp.DeleteForm(keyValue);
            return Success("删除成功。");
        }

        /// <summary>
        /// 来料登记生成存储
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult SaveStoreCell(string datas)
        {
            var stoRegisterEntityList = datas.ToList<CPK_11_DJ_StoRegisterEntity>();
            if (null == stoRegisterEntityList)
            {
                return Error("传入数据为空!");
            }
            cpk_11_DJ_StoRegisterApp.SaveStoreCell(stoRegisterEntityList);
            return Success("操作成功。");
        }

        #endregion 来料登记


        #region 存储
        /// <summary>
        /// 存储
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseStorage()
        {
            ViewBag.FAccountDate= GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }

        private string GetAccountDateForFinishedGoodsWareHouse()
        {
            return GetDocumentNum.GetNum(Configs.GetValue("UseUnit"), Configs.GetValue("FactoryFlag"), "台账日期成品", "admin", "", "临时");
        }

        /// <summary>
        /// 删除存储记录
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        [HttpPost]
        [HandlerAjaxOnly]
        public ActionResult DeleteStoStorageCard(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            cpk_21_CC_StoStorageCardApp.DeleteCC_StoStorageCard(data);
            return Success("操作成功。");
        }

        /// <summary>
        /// 修改存储信息
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public ActionResult EditStoStorageCard(CPK_21_CC_StoStorageCardEntity item)
        {
            if (null == item)
            {
                return Error("传入数据为空!");
            }
            cpk_21_CC_StoStorageCardApp.EditCC_StoStorageCard(item);
            return Success("操作成功。");
        }

        /// <summary>
        /// 打印存储卡
        /// </summary>
        /// <returns></returns>
        public ActionResult PrintStorgeCard()
        {
            return View();
        }
        /// <summary>
        /// 获取登记存储卡打印数据
        /// </summary>
        /// <param name="regids">存储卡id集合,格式:"a01,a02,a03"</param>
        /// <returns></returns>
        public ActionResult GetPrintStorgeCardData(string regids)
        {
            var data = v_cpk_21_CC_StoStorageCardApp.GetPrintData(regids);
            return Success(string.Format("获取到{0}条数据", data.Count), data.ToJson());
        }
        /// <summary>
        /// 获取档案存储卡打印数据
        /// </summary>
        /// <param name="regids">存储卡id集合,格式:"a01,a02,a03"</param>
        /// <returns></returns>
        public ActionResult GetPrintStorgeCardMidData(string regids)
        {
            var data = v_cpk_22_CK_StoStorageCard_MidApp.GetPrintStorgeCardMidData(regids);
            return Success(string.Format("获取到{0}条数据", data.Count), data.ToJson());
        }
        #endregion 存储

        #region 入库
        /// <summary>
        /// 选择入库信息
        /// </summary>
        /// <returns></returns>
        public ActionResult InStoreOrderInfo()
        {
            return View();
        }
        /// <summary>
        /// 入库
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseEnter()
        {
            ViewBag.FAccountDate = GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }

        /// <summary>
        /// 保存入库信息
        /// </summary>
        /// <param name="item">入库台帐</param>
        /// <param name="detail">入库明细</param>
        /// <returns></returns>
        public ActionResult SaveInStoreItem(CPK_41_ML_StoCPKConAccoEntity item, string detail)
        {
            CPK_42_MX_StoCPKListAccoEntity detailEntity = detail.ToObject<CPK_42_MX_StoCPKListAccoEntity>();
            KeyValuePair<bool, string> result = stoCPKConAccoForInStockApp.SaveInStoreItem(item, detailEntity);
            if (result.Key)
            {
                return Success("保存成功!", result.Value);
            }
            else
            {
                return Error(result.Key + "");
            }
        }

        public ActionResult EditInStoreDetail(CPK_42_MX_StoCPKListAccoEntity detail)
        {
            if (null == detail)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForInStockApp.EditInStoreDetail(detail);
            return Success("操作成功。");
        }

        public ActionResult DeleteInStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForInStockApp.DeleteInStoreItem(data);
            return Success("操作成功。");
        }

        public ActionResult AuditInStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            cpk_41_ML_StoCPKConAccoApp.AuditInStoreItem(data);
            return Success("操作成功。");
        }
        public ActionResult GetStoCPKConAccoItem(string fdocuno)
        {
            var data = cpk_41_ML_StoCPKConAccoApp.GetStoCPKConAcco(fdocuno);
            return Content(data.ToJson());
        }
        /// <summary>
        /// 入库冲红
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public ActionResult WriteOffInStoreItem(string keyValue)
        {
            if (string.IsNullOrEmpty(keyValue))
            {
                return Error("传入数据为空!");
            }
            KeyValuePair<bool, string> result = stoCPKConAccoForInStockApp.WriteOffInStoreItem(keyValue);
            if (result.Key)
            {
                return Success("入库信息冲红操作成功。", result.Value);
            }
            else
            {
                return Error(result.Value);
            }
        }
        /// <summary>
        /// 打印入库
        /// </summary>
        /// <returns></returns>
        public ActionResult PrintStockIn()
        {
            return View();
        }
        #endregion 入库

        #region 备料
        public ActionResult WareHouseMaterial()//备料
        {
            ViewBag.FAccountDate = GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }
        /// <summary>
        /// 保存备料单据
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ActionResult SavePrepare(string datas)//备料
        {
            var registerIDList = datas.ToList<CPK_31_BL_StoArcPreMaterialEntity>();
            if (null == registerIDList)
            {
                return Error("传入数据为空!");
            }
            cpk_31_BL_StoArcPreMaterialApp.SavePrepare(registerIDList);
            return Success("操作成功。");
        }

        public ActionResult EditPrepare(CPK_31_BL_StoArcPreMaterialEntity data)
        {
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            cpk_31_BL_StoArcPreMaterialApp.EditPrepare(data);
            return Success("操作成功。");
        }
        public ActionResult SavePrepareToOut(string datas)//备料生成出库
        {
            var registerIDList = datas.ToList<CPK_31_BL_StoArcPreMaterialEntity>();
            if (null == registerIDList)
            {
                return Error("传入数据为空!");
            }
            cpk_31_BL_StoArcPreMaterialApp.SavePrepareToOut(registerIDList);
            return Success("操作成功。");
        }
        /// <summary>
        /// 备料单打印
        /// </summary>
        /// <returns></returns>
        public ActionResult PrintPrepare()
        {
            return View();
        }
        #endregion 备料

        #region 出库
        public ActionResult WareHouseOut()//出库
        {
            ViewBag.FAccountDate = GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }
        /// <summary>
        /// 选择出库信息
        /// </summary>
        /// <returns></returns>
        public ActionResult OutStoreOrderInfo()
        {
            return View();
        }
        /// <summary>
        /// 保存出库单
        /// </summary>
        /// <param name="item">出库台帐</param>
        /// <param name="detail">出库明细</param>
        /// <returns></returns>
        public ActionResult SaveOutStoreItem(CPK_41_ML_StoCPKConAccoEntity item, string detail)
        {
            CPK_42_MX_StoCPKListAccoEntity detailentity = detail.ToObject<CPK_42_MX_StoCPKListAccoEntity>();
            item.FDocuTypeNO = "CC";
            KeyValuePair<bool, string> result = stoCPKConAccoForOutStockApp.SaveOutStoreItem(item, detailentity);
            if (result.Key)
            {
                return Success("保存成功!", result.Value);
            }
            else
            {
                return Error(result.Key + "");
            }
        }
        /// <summary>
        /// 删除出库单
        /// </summary>
        /// <param name="datas">单据号集合</param>
        /// <returns></returns>
        public ActionResult DeleteOutStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForOutStockApp.DeleteOutStoreItem(data);
            return Success("操作成功。");
        }

        /// <summary>
        /// 出库单审核
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ActionResult AuditOutStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForOutStockApp.AuditOutStoreItem(data);
            return Success("操作成功。");
        }

        /// <summary>
        /// 出库冲红
        /// </summary>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public ActionResult WriteOffOutStoreItem(string keyValue)
        {
            if (string.IsNullOrEmpty(keyValue))
            {
                return Error("传入数据为空!");
            }
            KeyValuePair<bool, string> result = stoCPKConAccoForOutStockApp.WriteOffOutStoreItem(keyValue);
            if (result.Key)
            {
                return Success("入库信息冲红操作成功。", result.Value);
            }
            else
            {
                return Error(result.Value);
            }
        }
        /// <summary>
        /// 打印出库
        /// </summary>
        /// <returns></returns>
        public ActionResult PrintStockOut()
        {
            return View();
        }
        #endregion 出库

        #region 废品件更换
        /// <summary>
        /// 选择废品件信息
        /// </summary>
        /// <returns></returns>
        public ActionResult UnqualifiedInfo()
        {
            return View();
        }
        /// <summary>
        /// 废品件登记
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseUnqualified()
        {
            ViewBag.FAccountDate = GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }
        /// <summary>
        /// 废品件输入
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseUnqualifiedInput()
        {
            return View();
        }

        /// <summary>
        /// 不合格品审核
        /// </summary>
        /// <returns></returns>
        public ActionResult AuditUnqualifiedItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForUnqualifiedStockApp.AuditUnqualifiedStoreItem(data);
            return Success("操作成功。");
        }

        /// <summary>
        /// 废品件出库
        /// </summary>
        /// <param name="item">废品件台帐</param>
        /// <param name="detail">废品件明细</param>
        /// <returns></returns>
        public ActionResult SaveUnqualifiedStoreItem(CPK_41_ML_StoCPKConAccoEntity item, string detail)
        {
            item.UseUnit = Configs.GetValue("UseUnit");
            CPK_42_MX_StoCPKListAccoEntity detailentity = detail.ToObject<CPK_42_MX_StoCPKListAccoEntity>();
            item.FDocuTypeNO = "CS";
            KeyValuePair<bool, string> result = stoCPKConAccoForUnqualifiedStockApp.SaveUnqualifiedStoreItem(item, detailentity);
            if (result.Key)
            {
                return Success("保存成功!", result.Value);
            }
            else
            {
                return Error(result.Key + "");
            }
        }


        /// <summary>
        /// 删除废品件出库单
        /// </summary>
        /// <param name="datas">单据号集合</param>
        /// <returns></returns>
        public ActionResult DeleteUnqualifiedStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForUnqualifiedStockApp.DeleteUnqualifiedStoreItem(data);
            return Success("操作成功。");
        }

        #endregion 废品件更换

        #region 返修品入库
        /// <summary>
        /// 选择返修品信息
        /// </summary>
        /// <returns></returns>
        public ActionResult ReturnRemainInfo()
        {
            return View();
        }

        public ActionResult WareHouseReturnRemain()//返修品
        {
            ViewBag.FAccountDate = GetAccountDateForFinishedGoodsWareHouse();
            return View();
        }
        public ActionResult WareHouseReturnRemainInput()//返修品新增
        {
            return View();
        }

        /// <summary>
        /// 保存返修品入库信息
        /// </summary>
        /// <param name="item">返修品台帐</param>
        /// <param name="detail">返修品明细</param>
        /// <returns></returns>
        public ActionResult SaveReturnRemainItem(CPK_41_ML_StoCPKConAccoEntity item, string detail)
        {
            item.UseUnit = Configs.GetValue("UseUnit");
            CPK_42_MX_StoCPKListAccoEntity detailentity = detail.ToObject<CPK_42_MX_StoCPKListAccoEntity>();
            item.FDocuTypeNO = "CX";
            KeyValuePair<bool, string> result = stoCPKConAccoForReturnRemainApp.SaveReturnRemainStoreItem(item, detailentity);
            if (result.Key)
            {
                return Success("保存成功!", result.Value);
            }
            else
            {
                return Error(result.Key + "");
            }
        }

        /// <summary>
        /// 删除返修单
        /// </summary>
        /// <param name="datas">单据号集合</param>
        /// <returns></returns>
        public ActionResult DeleteReturnRemainStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForOutStockApp.DeleteOutStoreItem(data);
            return Success("操作成功。");
        }

        /// <summary>
        /// 返修单审核
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public ActionResult AuditReturnRemainStoreItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            stoCPKConAccoForOutStockApp.AuditOutStoreItem(data);
            return Success("操作成功。");
        }

        #endregion 返修品入库

        #region 盘点
        /// <summary>
        /// 选择盘点信息
        /// </summary>
        /// <returns></returns>
        public ActionResult InventoryOrderInfo()
        {
            return View();
        }
        /// <summary>
        /// 盘点登记
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseInventory()
        {
            return View();
        }
        /// <summary>
        /// 盘点登记输入
        /// </summary>
        /// <returns></returns>
        public ActionResult WareHouseInventoryInput()
        {
            return View();
        }

        /// <summary>
        /// 保存盘点信息
        /// </summary>
        /// <param name="item">入库台帐</param>
        /// <param name="detail">入库明细</param>
        /// <returns></returns>
        public ActionResult SaveInventoryItem(CPK_41_ML_StoCPKConAccoEntity item, string detail)
        {
            CPK_42_MX_StoCPKListAccoEntity detailEntity = detail.ToObject<CPK_42_MX_StoCPKListAccoEntity>();
            item.FDocuTypeNO = "CP";
            KeyValuePair<bool, string> result = stoCPKConAccoForInventoryStockApp.SaveInventoryStoreItem(item,detailEntity);
            if (result.Key)
            {
                return Success("保存成功!", result.Value);
            }
            else
            {
                return Error(result.Key + "");
            }
        }
        /// <summary>
        /// 删除盘点记录
        /// </summary>
        /// <param name="datas">盘点单号集合</param>
        /// <returns></returns>
        public ActionResult DeleteInventoryItem(string datas)
        {
            var data = datas.ToList<string>();
            if (null == data)
            {
                return Error("传入数据为空!");
            }
            cpk_41_ML_StoCPKConAccoApp.DeleteCPKConAcco(data);
            return Success("操作成功。");
        }
        #endregion 盘点


        public ActionResult SaveDJ_StoRegisterCC(CPK_11_DJ_StoRegisterEntity item)
        {
            item.UseUnit = Configs.GetValue("UseUnit");
            item.FDocuTypeNO = "CC";
            item.FQuantity = item.FQuantity_KP;
            item.FCreateBy = OperatorProvider.Provider.GetCurrent().UserCode;
            item.FCreateDate = DateTime.Now.ToString("yyyy-MM-dd");
            item.FCreateTime = DateTime.Now.ToString("HH:mm:ss");
            cpk_11_DJ_StoRegisterApp.SubmitForm(item, item.FRegisterID);
            return Success("操作成功。");
        }
        public ActionResult DeleteDJ_StoRegisterCC(string keyValue)
        {
            if (string.IsNullOrEmpty(keyValue))
            {
                return Error("传入内容为空!");
            }
            cpk_11_DJ_StoRegisterApp.DeleteForm(keyValue);
            return Success("删除成功。");
        }
       

        public ActionResult GetInfoDocumentNum()
        {
            string DocNum = "";
            DocNum = GetDocumentNum.GetNum(Configs.GetValue("UseUnit"), Configs.GetValue("FactoryFlag"), "台账日期成品", "admin", DocNum, "临时");
            return Content(DocNum);
        }
        public ActionResult GetInfoDocumentNum2()//单据编号
        {
            string DocNum = "";
            DocNum = GetDocumentNum.GetNum(Configs.GetValue("UseUnit"), Configs.GetValue("FactoryFlag"), "来料条码", "admin", DocNum, "正式");
            return Content(DocNum);
        }

        public ActionResult SaveCC_StoStorageCard(string datas)
        {
            var registerIDList = datas.ToList<string>();
            if (null == registerIDList)
            {
                return Error("传入数据为空!");
            }
            cpk_21_CC_StoStorageCardApp.SaveCC_StoStorageCard(registerIDList);
            return Success("操作成功。");
        }

       
        public ActionResult DeleteEB_StoRegister(string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                cpk_42_MX_StoCPKListAccoApp.DeleteForm(keyValue);
                return Success("删除成功。");
            }
            return Success("删除失败。");
        }
    
        public ActionResult WareHouseMaterialBackup()
        {
            return View();
        }
        public ActionResult WareHouseMaterialInput()
        {
            return View();
        }
        public ActionResult WareHouseMaterialModi()
        {
            return View();
        }
        public ActionResult WareHouseMaterialPrint()
        {
            return View();
        }
       
        public ActionResult WareHouseOutInput()//出库
        {
            return View();
        }
        public ActionResult WareHouseOutModi()//出库
        {
            return View();
        }
        public ActionResult WareHouseOutCheck()//出库
        {
            return View();
        }
        public ActionResult WareHouseOutPrint()
        {
            return View();
        }
        public ActionResult WareHouseOutBill()
        {
            return View();
        }
        public ActionResult WareHouseReturnWaste()//废料返库登记
        {
            return View();
        }
        public ActionResult WareHouseReturnWasteInput()//废料返库登记
        {
            return View();
        }
        public ActionResult WareHouseReturnWasteModi()//废料返库登记
        {
            return View();
        }
        public ActionResult WareHouseReturnWasteCheck()//废料返库登记
        {
            return View();
        }
       
       
        public ActionResult WareHouseRecSendStatistics()//原材料仓库收发综合统计表
        {
            return View();
        }
        public ActionResult WareHouseRecSendSaveStatistics()//原材料仓库收发存统计表
        {
            return View();
        }

        public ActionResult WareHouseLedger()//库存明细台帐
        {
            ViewData["productUnitList"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(GetProductUnit());

            ViewData["sparePartsList"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(GetSpareParts());

            ViewData["LedgerDate"] = GetInfoDocumentNumBy();

            return View();
        }
        public ActionResult WareHouseLedgerBill()//库存明细台帐
        {
            return View();
        }
        public ActionResult WareHouseLedgerPrint()//库存明细台帐
        {
            return View();
        }
        public ActionResult WareHouseReport()//库统计报表
        {
            return View();
        }


       

        public ActionResult WareHouseEnterInput()
        {
            return View();
        }
        public ActionResult WareHouseNotice()
        {
            return View();
        }
      

        public ActionResult WareHouseEnterInternal()
        {
            return View();
        }
        public ActionResult WareHouseEnterBill()
        {
            return View();
        }
        public ActionResult WareHouseEnterBillPrint()
        {
            return View();
        }
        public ActionResult WareHouseStorageInput()
        {
            return View();
        }


        public ActionResult WareHouseStorageModi()
        {
            return View();
        }

        public ActionResult WareHouseStoresRepair()
        {
            return View();
        }
        public ActionResult WareHouseStoresBack()
        {
            return View();
        }
        public ActionResult WareHouseStoresOther()
        {
            return View();
        }


        public ActionResult WareHouseEleBill()
        {
            return View();
        }

        public ActionResult WareHouseInOut()
        {
            return View();
        }
        //
        // GET: /WareHouse/EnterWareHouse/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        public ActionResult WareHouseNoticeInput()
        {
            return View();
        }
        public ActionResult WareHouseNoticeModi()
        {
            return View();
        }
        public ActionResult WareHouseStorageCard()
        {
            return View();
        }
        //
        // GET: /WareHouse/EnterWareHouse/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /WareHouse/EnterWareHouse/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /WareHouse/EnterWareHouse/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        public ActionResult StatisticLedger()
        {
            ViewData["productUnitList"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(GetProductUnit());

            ViewData["sparePartsList"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(GetSpareParts());

            ViewData["LedgerDate"] = GetInfoDocumentNumBy();

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curUnit"] = GetSupplierInfo(Configs.GetValue("UseUnit"));

            ViewData["curDate"] = DateTime.Now.ToString("yyyy/MM/dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            return View();
        }

        public ActionResult StatisticLedgerDetails(string param,string FAccountDate)
        {
            Dictionary<string, string> parames = null;

            bool isCurrent = false;

            parames = DeserializeJson<Dictionary<string, string>>(param);

            parames["制造单位名称"] = string.Format("{0} {1}", parames["制造单位"], parames["制造单位名称"]);

            parames["零件分类"] = string.Format("{0} {1}", parames["分类编号"], parames["零件分类"]);

            parames["FAccountDate"] = FAccountDate;
            //零件编号,单价 （元）,最低储备,最高储备,制造单位名称,零件分类
            ViewData["零件名称"] = parames["零件名称"] ?? string.Empty;

            ViewData["零件编号"] = parames["零件编号"] ?? string.Empty;

            ViewData["核算单价"] = parames["单价 （元）"] ?? "0.00";

            ViewData["最低储备"] = parames["最低储备"]?? "";

            ViewData["最高储备"] = parames["最高储备"] ?? "";

            ViewData["制造单位名称"] = parames["制造单位名称"] ?? string.Empty;

            ViewData["零件分类"] = parames["零件分类"] ?? string.Empty;

            ViewData["jsonData"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(parames);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy/MM/dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            isCurrent = GetInfoDocumentNumBy().Equals(FAccountDate);

            List<Dictionary<string, object>> listData = GetStatisticLedgersDetailList(isCurrent, FAccountDate, parames["零件编号"], parames["分类编号"], parames["制造单位"]);

            ViewData["listData"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(listData); ;

            return View();
        }

        public ActionResult WareHouseLedgerDetails(string param,string FAccountDate)
        {
            Dictionary<string, string> parames = null;

            bool isCurrent = false;

            parames = DeserializeJson<Dictionary<string, string>>(param);
            
            parames["制造单位名称"] = string.Format("{0} {1}", parames["制造单位"], parames["制造单位名称"]);

            parames["零件分类"] = string.Format("{0} {1}", parames["分类编号"], parames["零件分类"]);

            parames["FAccountDate"] = FAccountDate;
            //零件名称,零件编号,Fprice_X,FLowestStore,制造单位名称,零件分类
            ViewData["零件名称"] = parames["零件名称"];

            ViewData["零件编号"] = parames["零件编号"];

            ViewData["Fprice_X"] = parames["单价 （元）"]??"0.00";

            ViewData["FHighestStore"] = parames["最高储备"] ?? string.Empty;

            ViewData["FLowestStore"] = parames["最低储备"] ?? string.Empty;

            ViewData["制造单位名称"] = parames["制造单位名称"];

            ViewData["零件分类"] = parames["零件分类"];

            ViewData["jsonData"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(parames);

            ViewData["curUserName"] = OperatorProvider.Provider.GetCurrent().UserName;

            ViewData["curDate"] = DateTime.Now.ToString("yyyy/MM/dd");

            ViewData["curTime"] = DateTime.Now.ToString("HH:mm:ss");

            isCurrent = GetInfoDocumentNumBy().Equals(FAccountDate);

            List<Dictionary<string, object>> listData = GetLedgersDetailList(isCurrent, FAccountDate, parames["零件编号"], parames["分类编号"], parames["制造单位"]);

            ViewData["listData"] = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(listData); ;

            return View();
        }

        private List<Hashtable> GetProductUnit()
        {
            List<Hashtable> list = null;

            string sql = "SELECT  UnitNO,UnitShortName  FROM  ZSJ_B1_GH_SupplierInformation  WHERE UseUnit ='{0}' AND  IsProduct ='1'  ORDER BY UnitNO";

            list = new List<Hashtable>();

            sql = string.Format(sql, ConfigurationManager.AppSettings["UseUnit"]);

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                try
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(sql, conn);

                    IDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Hashtable item = new Hashtable();

                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            item.Add(reader.GetName(i), reader[i]);
                        }

                        list.Add(item);
                    }

                }
                finally
                {
                    conn.Close();
                }

            }

            return list;
        }

        private List<Hashtable> GetSpareParts()
        {
            List<Hashtable> list = null;

            string sql = "SELECT FTypeNO,FTypeName  FROM V_BUS_SJ_Dictionary WHERE UseUnit ='{0}'  and  FClassNO ='01'  ORDER  BY SortCode";

            list = new List<Hashtable>();

            sql = string.Format(sql, ConfigurationManager.AppSettings["UseUnit"]);

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                try
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(sql, conn);

                    IDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Hashtable item = new Hashtable();

                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            item.Add(reader.GetName(i), reader[i]);
                        }

                        list.Add(item);
                    }

                }
                finally
                {
                    conn.Close();
                }

            }

            return list;
        }

        private string GetInfoDocumentNumBy()
        {
            string result = string.Empty;

            try
            {
                result = GetDocumentNum.GetNum(Configs.GetValue("UseUnit"), Configs.GetValue("FactoryFlag"), "台账日期成品", "admin", result, "临时");
            }
            catch
            {
                result = DateTime.Now.ToString("yyyyMM");
            }

            return result;
        }



        public ActionResult GetLedgers(string param)
        {
            List<Dictionary<string, object>> result = null;

            Hashtable resp = null;

            StringBuilder con = null;

            Dictionary<string, string> parames = null;

            int status = 0;

            try
            {
                resp = new Hashtable();

                parames = DeserializeJson<Dictionary<string, string>>(param);

                con = new StringBuilder();

                result = new List<Dictionary<string, object>>();

                string sql = @" SELECT DISTINCT UseUnit,FAccountDate,FProductionNO AS 零件编号,FProductionName AS 零件名称,FProCompanyNO AS 制造单位,FProCompanyName AS 制造单位名称,FProductionTypeNO ,FProductionTypeName as 零件分类,Fprice_X,FSafetystore,FLowestStore,FHighestStore FROM dbo.V_CPK_44_MX_StoCPKListAcco_Mid_MXZMX WHERE UseUnit = '{1}' AND FAccountDate = '{0}'  {2} order by FProductionNO,FProCompanyNO";

                if ("0".Equals(parames["isCurrent"]))
                {
                    sql = @"SELECT DISTINCT UseUnit,FAccountDate,FProductionNO AS 零件编号,FProductionName  AS 零件名称,FProCompanyNO AS 制造单位,FProCompanyName AS 制造单位名称,FProductionTypeNO,FProductionTypeName as 零件分类,Fprice_X,FSafetystore,FLowestStore,FHighestStore  FROM V_CPK_47_MX_StoCPKListAcco_Arc_MXZMX  WHERE UseUnit =' {1} ' AND FAccountDate ='{0}' {2}  order  by FProductionNO,FProCompanyNO";
                }

                if (!string.Empty.Equals(parames["pu"]))
                {
                    con.Append(string.Format(" and FProCompanyNO = '{0}' ", parames["pu"]));
                }

                if (!string.Empty.Equals(parames["sp"]))
                {
                    con.Append(string.Format(" and  FProductionTypeNO = '{0}' ", parames["sp"]));
                }

                if (!string.Empty.Equals(parames["no"]))
                {
                    con.Append(string.Format("  and FProductionNO = '{0}' ", parames["no"]));
                }

                if (!string.Empty.Equals(parames["name"]))
                {
                    con.Append(string.Format("  and FProductionName like '%{0}%' ", parames["name"]));
                }

                sql = string.Format(sql, parames["date"], Configs.GetValue("UseUnit").Trim(), con);

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    try
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(sql, conn);

                        IDataReader reader = cmd.ExecuteReader();

                        int count = 0;

                        while (reader.Read())
                        {
                            Dictionary<string, object> item = new Dictionary<string, object>();

                            item.Add("序号", ++count);

                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                item.Add(reader.GetName(i), reader[i]);
                            }

                            item.Add("备注", string.Empty);

                            result.Add(item);
                        }

                        resp.Add("content", result);
                    }
                    finally
                    {
                        conn.Close();
                    }

                }
            }
            catch (Exception ex)
            {
                resp.Add("err_msg", ex.Message);

                status = ex.GetHashCode();
            }

            resp.Add("status", status);

            return Content(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(resp));
        }

        public List<Dictionary<string, object>> GetLedgersDetailList(bool isCurrent, string date, string no, string sp, string pu)
        {
            List<Dictionary<string, object>> result = null;

            StringBuilder con = null;

            try
            {
                result = new List<Dictionary<string, object>>();

                con = new StringBuilder();

                string sql = @" SELECT FCurDate 日期,FDocuNO 单据编号,FHappenComNO 发生单位,FHappenComName 发生单位名称,FDocuTypeNO,FDocuTypeName 摘要,FCredence 凭证编号,FBatchNo 批次号,0 期初,FQuantity_QC,isnull(FQuantity_RK,0) 入库,isnull(FQuantity_CK,0) 出库,isnull(FQuantity_FP,0) 废品,isnull(FQuantity_FX,0) 返修,isnull(FQuantity_PC,0) 盈亏,0 结存数量,isnull(Fprice_X,0) ""单价（元）"",0 ""结存金额（元）"" ,FSupplierNO 来料单位,FSupplierName 来料单位名称,FStoreSetNO 仓库定置,FSourceDouNO 入库单号 from V_CPK_44_MX_StoCPKListAcco_Mid_MXZMX  WHERE UseUnit ='{1}' AND FAccountDate ='{0}' {2} order  by FCreateDate ,FCreateTime ";

                if (!isCurrent)
                {
                    sql = @" SELECT FCurDate 日期,FDocuNO 单据编号,FHappenComNO 发生单位,FHappenComName 发生单位名称,FDocuTypeNO,FDocuTypeName 摘要,FCredence 凭证编号,FBatchNo 批次号,0 期初,FQuantity_QC,isnull(FQuantity_RK,0) 入库,isnull(FQuantity_CK,0) 出库,isnull(FQuantity_FP,0) 废品,isnull(FQuantity_FX,0) 返修,isnull(FQuantity_PC,0) 盈亏,0 结存数量,isnull(Fprice_X,0) ""单价（元）"",0 ""结存金额（元）"" ,FSupplierNO 来料单位,FSupplierName 来料单位名称,FStoreSetNO 仓库定置,FSourceDouNO 入库单号 from V_CPK_47_MX_StoCPKListAcco_Arc_MXZMX  WHERE UseUnit ='{1}' AND FAccountDate ='{0}' {2} order  by FCreateDate ,FCreateTime ";
                }
                //and FProductionNO ='" + 选择的零件编号 + "' AND FProductionTypeNO ='" + 选择的零件分类 + "' AND FProCompanyNO ='" + 选择的制造单位编码 + "'
                if (!string.Empty.Equals(no))
                {
                    con.Append(string.Format("  and FProductionNO = '{0}' ", no));
                }

                if (!string.Empty.Equals(sp))
                {
                    con.Append(string.Format(" and  FProductionTypeNO = '{0}' ", sp));
                }

                if (!string.Empty.Equals(pu))
                {
                    con.Append(string.Format(" and FProCompanyNO = '{0}' ", pu));
                }

                sql = string.Format(sql, date, Configs.GetValue("UseUnit").Trim(),con.ToString());

                ViewData["sql"] = sql;

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    try
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(sql, conn);

                        IDataReader reader = cmd.ExecuteReader();

                        int count = 0;

                        int last = 0;

                        while (reader.Read())
                        {
                            Dictionary<string, object> item = new Dictionary<string, object>();

                            item.Add("序号",++count);

                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                item.Add(reader.GetName(i), reader[i]);
                            }

                            if (0 != last)
                            {
                                item["期初"] = last;
                            }
                            else
                            {
                                item["期初"] = item["FQuantity_QC"];
                            }

                            item["结存数量"] = Convert.ToInt32(item["期初"]) + Convert.ToInt32(item["入库"])
                            - Convert.ToInt32(item["出库"])
                            - Convert.ToInt32(item["废品"])
                            + Convert.ToInt32(item["返修"])
                            + Convert.ToInt32(item["盈亏"]);

                            item["结存金额（元）"] = Convert.ToDecimal(item["结存数量"]) * Convert.ToDecimal(item["单价（元）"]);

                            if (item["结存金额（元）"].ToString().Equals("0.0000"))
                            {
                                item["结存金额（元）"] = "0.00";
                            }

                            if (item["单价（元）"].ToString().Equals("0.0000"))
                            {
                                item["单价（元）"] = "0.00";
                            }

                            if (item["入库"].ToString().Equals("0"))
                            {
                                item["入库"] = "";
                            }

                            if (item["出库"].ToString().Equals("0"))
                            {
                                item["出库"] = "";
                            }

                            if (item["废品"].ToString().Equals("0"))
                            {
                                item["废品"] = "";
                            }

                            if (item["返修"].ToString().Equals("0"))
                            {
                                item["返修"] = "";
                            }

                            if (item["盈亏"].ToString().Equals("0"))
                            {
                                item["盈亏"] = "";
                            }

                            last = Convert.ToInt32(item["结存数量"]);

                            item[" "] = string.Empty;

                            result.Add(item);
                        }
                    }
                    finally
                    {
                        conn.Close();
                    }

                }
            }
            catch
            {

            }

            return result;
        }

        public ActionResult GetStatisticLedgers(string param)
        {
            List<Dictionary<string, object>> result = null;

            Hashtable resp = null;

            StringBuilder con = null;

            Dictionary<string, string> parames = null;

            int status = 0;

            try
            {
                resp = new Hashtable();

                parames = DeserializeJson<Dictionary<string, string>>(param);

                con = new StringBuilder();

                result = new List<Dictionary<string, object>>();

                string sql = @" SELECT
	FProductionNO 零件编号,
	FProductionName 零件名称,
	FImmeQuantity 即时库存,
	FBookQuantity 账面库存,
	FSafetystore 安全储备,
	FHighestStore 最高储备,
	FLowestStore 最低储备,
	FDailyConsume 日均消耗,
	Fprice_X ""单价 （元）"",
    FBookMoney ""账面金额（元）"",
	FProCompanyNO 制造单位,
    FProCompanyName 制造单位名称,
	FProductionTypeNO 分类编号,
    FProductionTypeName 零件分类
        FROM
            dbo.V_CPK_71_KC_StoCPKStockCata
        WHERE
            UseUnit = '{1}'
        AND FAccountDate = '{0}'
         {2}
        ORDER BY
            FProductionNO,
	        FProductionName";

                if ("0".Equals(parames["isCurrent"]))
                {
                    sql = @"SELECT
		                    FProductionNO 零件编号,
	                    FProductionName 零件名称,
	                    FImmeQuantity 即时库存,
	                    FBookQuantity 账面库存,
	                    FSafetystore 安全储备,
	                    FHighestStore 最高储备,
	                    FLowestStore 最低储备,
	                    FDailyConsume 日均消耗,
	                    isnull(Fprice_X,0.0) ""单价 （元）"",
                        isnull(FBookMoney,0.0) ""账面金额（元）"",
	                    FProCompanyNO 制造单位,
                        FProCompanyName 制造单位名称,
	                    FProductionTypeNO 分类编号,
                        FProductionTypeName 零件分类
                        FROM
                            dbo.V_CPK_72_KC_StoCPKStockCata_Arc
                        WHERE
                            UseUnit = '{1}'
                        AND FAccountDate = '{0}'
                         {2}
                        ORDER BY
                            FProductionNO,
		                    FProductionName";
                }

                if (!string.Empty.Equals(parames["pu"]))
                {
                    con.Append(string.Format(" and FProCompanyNO = '{0}' ", parames["pu"]));
                }

                if (!string.Empty.Equals(parames["sp"]))
                {
                    con.Append(string.Format(" and  FProductionTypeNO = '{0}' ", parames["sp"]));
                }

                if (!string.Empty.Equals(parames["no"]))
                {
                    con.Append(string.Format("  and FProductionNO = '{0}' ", parames["no"]));
                }

                if (!string.Empty.Equals(parames["name"]))
                {
                    con.Append(string.Format("  and FProductionName like '%{0}%' ", parames["name"]));
                }

                sql = string.Format(sql, parames["date"], Configs.GetValue("UseUnit").Trim(), con);

                ViewData["sql"] = sql;

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    try
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(sql, conn);

                        IDataReader reader = cmd.ExecuteReader();

                        int count = 0;

                        while (reader.Read())
                        {
                            Dictionary<string, object> item = new Dictionary<string, object>();

                            item.Add("序号", ++count);

                            item.Add("操作", "操作");

                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                item.Add(reader.GetName(i), reader[i]);
                            }

                            if (item["账面金额（元）"].ToString().Equals("0.00000000"))
                            {
                                item["账面金额（元）"] = "0.00";
                            }

                            if (item["单价 （元）"].ToString().Equals(string.Empty))
                            {
                                item["单价 （元）"] = "0.00";
                            }


                            item.Add("备注", string.Empty);

                            result.Add(item);
                        }

                        resp.Add("content", result);
                    }
                    finally
                    {
                        conn.Close();
                    }

                }
            }
            catch (Exception ex)
            {
                resp.Add("err_msg", ex.Message);

                status = ex.GetHashCode();
            }

            resp.Add("status", status);

            return Content(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(resp));
        }

        public ActionResult GetStatisticLedgersJSONData(Pagination pagination, string param)
        {
            Dictionary<string, string> parames = null;

            bool isCurrent = false;

            string FProCompanyNO = string.Empty, FProductionTypeNO = string.Empty, FProductionNO = string.Empty, FProductionName = string.Empty, FAccountDate = string.Empty, UseUnit = string.Empty;

            parames = DeserializeJson<Dictionary<string, string>>(param);

            isCurrent = "1".Equals(parames["isCurrent"]);

            FProCompanyNO = parames["pu"];

            FProductionTypeNO = parames["sp"];

            FProductionNO = parames["no"];

            FProductionName = parames["name"];

            FAccountDate = parames["date"];

            UseUnit = Configs.GetValue("UseUnit").Trim();

            var data = new
            {
                rows = dutyApp.GetStatisticLedgersJSONData(pagination, isCurrent, FProCompanyNO, FProductionTypeNO, FProductionNO, FProductionName, FAccountDate, UseUnit),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };

            return Content(data.ToJson());
        }



        public List<Dictionary<string, object>> GetStatisticLedgersDetailList(bool isCurrent, string date, string no, string sp, string pu)
        {
            List<Dictionary<string, object>> result = null;

            StringBuilder con = null;

            try
            {
                result = new List<Dictionary<string, object>>();

                con = new StringBuilder();

                string sql = @"SELECT 	                        FCurDate 发生日期, 	                        FHappenComNO 发生单位, 	                        FHappenComName 发生单位名称, 	                        isnull(FQuantity_QC,0) FQuantity_QC,                            0 期初数量, 	                        isnull(FQuantity_RK,0) 入库数量, 	                        isnull(FQuantity_CK,0) 出库数量, 	                        isnull(FQuantity_FP,0) 废品数量, 	                        isnull(FQuantity_FX,0) 返修数量, 	                        isnull(FQuantity_PC,0) 盈亏数量,                           0 库存数量, 	                        isnull(Fprice_X,0) ""单价（元）"",                            0 ""库存金额（元）""                         FROM                             V_CPK_44_MX_StoCPKListAcco_Mid_TJMX                         WHERE                             UseUnit = '{1}'                         AND FAccountDate = '{0}'                         {2}                         ORDER BY                             FCurDate";

                if (!isCurrent)
                {
                    sql = @" SELECT FCurDate 日期,FDocuNO 单据编号,FHappenComNO 发生单位,FHappenComName 发生单位名称,FDocuTypeNO,FDocuTypeName 摘要,FCredence 凭证编号,0 期初,FBatchNo 批次号,isnull(FQuantity_QC,0) FQuantity_QC,isnull(FQuantity_RK,0) 入库,isnull(FQuantity_CK,0) 出库,isnull(FQuantity_FP,0) 废品,isnull(FQuantity_FX,0) 返修,isnull(FQuantity_PC,0) 盈亏,0 结存数量,isnull(Fprice_X,0) ""单价（元）"",0 ""结存金额（元）"" ,FSupplierNO 来料单位,FSupplierName 来料单位名称,FStoreSetNO 仓库定置,FSourceDouNO 入库单号 from V_CPK_47_MX_StoCPKListAcco_Arc_MXZMX  WHERE UseUnit ='{1}' AND FAccountDate ='{0}' {2} order  by FCreateDate ,FCreateTime ";
                }
                //and FProductionNO ='" + 选择的零件编号 + "' AND FProductionTypeNO ='" + 选择的零件分类 + "' AND FProCompanyNO ='" + 选择的制造单位编码 + "'
                if (!string.Empty.Equals(no))
                {
                    con.Append(string.Format("  and FProductionNO = '{0}' ", no));
                }

                if (!string.Empty.Equals(sp))
                {
                    con.Append(string.Format(" and  FProductionTypeNO = '{0}' ", sp));
                }

                if (!string.Empty.Equals(pu))
                {
                    con.Append(string.Format(" and FProCompanyNO = '{0}' ", pu));
                }

                sql = string.Format(sql, date, Configs.GetValue("UseUnit").Trim(), con.ToString());

                ViewData["sql"] = sql;

                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    try
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(sql, conn);

                        IDataReader reader = cmd.ExecuteReader();

                        int count = 0;

                        int last = 0;

                        while (reader.Read())
                        {
                            Dictionary<string, object> item = new Dictionary<string, object>();

                            item.Add("序号", ++count);

                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                item.Add(reader.GetName(i), reader[i]);
                            }

                            if (0 != last)
                            {
                                item["期初数量"] = last;
                            }
                            else
                            {
                                item["期初数量"] = item["FQuantity_QC"];
                            }
                            
                            item["库存数量"] = Convert.ToInt32(DBNull.Value == item["期初数量"] ? 0 : item["期初数量"]) + Convert.ToInt32(DBNull.Value == item["入库数量"] ? 0 : item["入库数量"])
                            - Convert.ToInt32(DBNull.Value == item["出库数量"] ? 0 : item["出库数量"])
                            - Convert.ToInt32(DBNull.Value == item["废品数量"] ? 0 : item["废品数量"])
                            + Convert.ToInt32(DBNull.Value == item["返修数量"] ? 0 : item["返修数量"])
                            + Convert.ToInt32(DBNull.Value == item["盈亏数量"] ? 0 : item["盈亏数量"]);

                            item["库存金额（元）"] = Convert.ToDecimal(item["库存数量"]) * Convert.ToDecimal(item["单价（元）"]);

                            if (item["库存金额（元）"].ToString().Equals("0.0000"))
                            {
                                item["库存金额（元）"] = "0.00";
                            }

                            if (item["单价（元）"].ToString().Equals("0.0000"))
                            {
                                item["单价（元）"] = "0.00";
                            }

                            if (item["入库数量"].ToString().Equals("0"))
                            {
                                item["入库数量"] = "";
                            }

                            if (item["出库数量"].ToString().Equals("0"))
                            {
                                item["出库数量"] = "";
                            }

                            if (item["废品数量"].ToString().Equals("0"))
                            {
                                item["废品数量"] = "";
                            }

                            if (item["返修数量"].ToString().Equals("0"))
                            {
                                item["返修数量"] = "";
                            }

                            if (item["盈亏数量"].ToString().Equals("0"))
                            {
                                item["盈亏数量"] = "";
                            }

                            last = Convert.ToInt32(item["库存数量"]);

                            item.Add(" ", "");

                            result.Add(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {

                        conn.Close();
                    }

                }
            }
            catch
            {

            }

            return result;
        }

        private string GetSupplierInfo(string unitNo)
        {
            string result = string.Empty;

            string sql = @"select UnitFullName  from ZSJ_B1_GH_SupplierInformation
            where unitno = @unitno";

            SqlParameter par = new SqlParameter("@unitno", unitNo);

            try
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    try
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand(sql, conn);

                        cmd.Parameters.Add(par);

                        result = Convert.ToString(cmd.ExecuteScalar());
                    }
                    finally
                    {
                        conn.Close();
                    }

                }
            }
            catch
            {

            }

            return result;
        }



        public T DeserializeJson<T>(string jsonString)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return serializer.Deserialize<T>(jsonString);
        }


    }
}
